*********************
**# A. 1930 Swiss IV
*********************
// use "raw/tariffLine_tariffs_1930.dta", clear
// 	* Tariff line 1930 data from Greenland & Lopresti (2024) "Trade policy as an exogenous shock: Focusing on the specifics"
//	* This paper, and the associated data, has not yet been published 
// drop if inlist(rate_prov,18,58)
// collapse calc_duties values, by(class matched_sitc)
// gen ave_start = calc_duties/values
// gen ave_end= .14*ave_start/(.14+ave_start)
// rename matched_sitc_final sitc2
// drop if regexm(sitc2,",") == 1
// replace sitc2 = substr(sitc2,1,4)
//
// collapse (mean) ave_start ave_end [aw=values], by(sitc2)
//
// gen year = 1930
//
// merge 1:m sitc2 using "processing/sic_sitc2_concordance"
// keep if _m == 3
// drop _m
//
// *Scale up weights to sum to 1 within SIC
// egen scale = total(sic_sitc_weight), by(sic)
//
// replace sic_sitc_weight = sic_sitc_weight/scale
//
// collapse (mean) ave_start ave_end [aw=sic_sitc_weight], by(sic year)
//
// gen ave_swiss_change_1930 = ln(1+ave_end)-ln(1+ave_start)
// drop if regexm(sic,"X") == 1
// destring sic, replace
// keep sic ave_swiss_change_1930 ave_start
// rename ave_start ave_1930
//
// keep if inrange(sic, 2000,3999)
// save "analysis/swiss_1930.dta", replace
//	* We provide "swiss_1930.dta" in raw/swiss_1930.dta


**********************
**# B. 1930s controls
**********************

********************************************
**## B.1 1930 Census of Manuf emp by gender
********************************************
import excel "raw/census1930_table5_gender.xlsx", sheet("Sheet3") firstrow clear

replace Industry = lower(Industry)
replace Industry = "collars, men's" if regexm(Industry,"collars") == 1
replace Industry = "confectionery" if Industry == "confectionary"
replace Industry = "embroideries" if Industry == "embrolderles"
replace Industry = "fertilizers" if Industry == "fertillzers"
replace Industry = "knit goods" if regexm(Industry, "knit goods") == 1
replace Industry = "photographic apparatus" if regexm(Industry,"photographic app") == 1
replace Industry = "poultry killing, dressing, and packing" if regexm(Industry, "poulty killing") == 1
replace Industry = "sausage, meat puddings, headcheese" if regexm(Industry, "meat puddings") == 1
replace Industry = "suspenders, garters, and other" if regexm(Industry, "suspenders, ga") == 1
replace Industry = "liquor vinous" if Industry == "liquor, vinous"
replace Industry = "musical instruemnts: pianos" if Industry == "musical instruments: pianos"

gen female_share = Female/Total
keep if CensusYear == 1929
keep female_share Industry CensusYear

save "processing/female_share_temp.dta", replace


*********************************************
**## B.2 1930 Census of Manuf other controls
*********************************************
import excel "raw/census1930_table5.xlsx", sheet("Sheet2") firstrow clear

keep if CensusYear == 1929 | CensusYear == 1927
replace Industry = lower(Industry)
replace Industry = "collars, men's" if regexm(Industry,"collars") == 1
replace Industry = "confectionery" if Industry == "confectionary"
replace Industry = "embroideries" if Industry == "embrolderles"
replace Industry = "fertilizers" if Industry == "fertillzers"
replace Industry = "knit goods" if regexm(Industry, "knit goods") == 1
replace Industry = "photographic apparatus" if regexm(Industry,"photographic app") == 1
replace Industry = "poultry killing, dressing, and packing" if regexm(Industry, "poulty killing") == 1
replace Industry = "sausage, meat puddings, headcheese" if regexm(Industry, "meat puddings") == 1
replace Industry = "suspenders, garters, and other" if regexm(Industry, "suspenders, ga") == 1
replace Industry = "liquor vinous" if Industry == "liquor, vinous"
replace Industry = "musical instruemnts: pianos" if Industry == "musical instruments: pianos"

replace ProprietorsandFirmMembers = "." if ProprietorsandFirmMembers == "-"
destring ProprietorsandFirmMembers Horsepower, replace
replace ProprietorsandFirmMembers = 0 if ProprietorsandFirmMembers == .
replace Horsepower = 0 if Horsepower == .

* Several Industries Have Multiple Observations for 1927
drop if Industry == "foundry and machine-shop products not elsewhere classified" & CensusY == 1927 & Number == 8380
drop if Industry == "machine tools" & CensusY == 1927 & Number == 355
drop if Industry == "tools, not including edge tools, machine tools, files, or saws" & CensusY == 1927 & Number == 657

merge 1:1 Industry CensusYear using "processing/female_share_temp"
drop if _m == 2
drop _merge

egen ind_group = group(Industry)
xtset ind_group CensusYear
gen invest = ln(Horsepower)-ln(l2.Horsepower)

gen skilled_share = SalariedOfficersandEmployees/(SalariedOfficersandEmployees+WageEarnersAveragefortheYe)

gen hp_per_worker = ln(Horsepower/Total)

gen mat_ship = CostofMaterialsContainersF/ValueofProducts

drop if invest == .

keep skilled_share hp_per_worker mat_ship invest Industry ValueofProducts female_share

merge 1:m Industry using "processing/sic_census_concordance_1930_clean"
keep if _m == 3
drop _m

* Share of value within an SIC accounted for by each industry
egen totship = total(ValueofProducts), by(sic87)
gen share = ValueofProducts/totship

foreach x of varlist skilled_share hp_per_worker mat_ship invest female_share {
	replace `x' = `x'*share
}

collapse (sum) skilled_share hp_per_worker mat_ship invest female_share, by(sic)
 
rename (skilled_share hp_per_worker mat_ship invest female_share) ///
(skilled_share_1930 hp_per_worker_1930 mat_ship_1930 invest_1930 female_share_1930)

rename sic sic4
tostring sic4, replace

label var skilled_share_1930 "\$ \frac{Emp_{Salaried,i,1929}}{Emp_{i,1929}}   \$"
label var hp_per_worker_1930 "\$ \ln( \frac{HP_{i,1929}}{Employment_{i,1929}} )  \$"
label var mat_ship_1930 "\$\frac{Materials_{i,1929}}{Shipments_{i,1929}}\$"
label var female_share_1930 "\$ \frac{Emp_{Women,i,1929}}{Emp_{i,1929}}   \$"
label var invest_1930 "\$ \Delta \ln(HP_{i,1927-1929}) \$"
label var sic4 "4-digit SIC industry"
save "analysis/com_controls_clean", replace

